package com.wwwarehouse.usercenter.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.bean.response.DistributePermissionArrayBean;

import java.util.ArrayList;


/**
 * 权限分配->错误详情
 * Created by ShineF on 2017/9/25 0025.
 */

public class DistributePermissionErrorDetailsListAdapter extends BaseAdapter {


    private Context mContext;
    private int mHeight;
    private ArrayList<DistributePermissionArrayBean> mDataList;


    public DistributePermissionErrorDetailsListAdapter(Context context, int mHeight, ArrayList<DistributePermissionArrayBean> dataList) {
        this.mContext = context;
        this.mHeight = mHeight;
        this.mDataList = dataList;
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }

    @Override
    public Object getItem(int i) {
        return mDataList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = View.inflate(mContext, R.layout.adapter_distribute_permission_error, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.mRlItem.getLayoutParams();
        params.height = mHeight;
        DistributePermissionArrayBean bean = mDataList.get(i);
        if (bean.getUserName() == null) {
            holder.mTvUserName.setVisibility(View.INVISIBLE);
            holder.mTvContent.setVisibility(View.VISIBLE);
            holder.mTvContentMsg.setVisibility(View.VISIBLE);
            holder.mTvContent.setText(bean.getAuthName());
            holder.mTvContentMsg.setText(bean.getDetailMsg());
        } else if (bean.getAuthName() == null || bean.getDetailMsg() == null) {
            holder.mTvUserName.setVisibility(View.VISIBLE);
            holder.mTvContent.setVisibility(View.INVISIBLE);
            holder.mTvContentMsg.setVisibility(View.INVISIBLE);
            holder.mTvUserName.setText(bean.getUserName());
        }
        return view;
    }

    private class ViewHolder {

        RelativeLayout mRlItem;
        TextView mTvContent;
        TextView mTvUserName;
        TextView mTvContentMsg;

        ViewHolder(View view) {
            mRlItem = (RelativeLayout) view.findViewById(R.id.rl_item);
            mTvContent = (TextView) view.findViewById(R.id.tv_content);
            mTvUserName = (TextView) view.findViewById(R.id.tv_user_name);
            mTvContentMsg = (TextView) view.findViewById(R.id.tv_content_msg);
        }
    }
}
